var WebClients = {
    createNew: function(Socket) {
        var WebClient = {};
        WebClient.Id = new Date().getTime().toString();
        WebClient.Socket = Socket;
        WebClient.Name = [];
        WebClient.subscribers = {};
        WebClient.on = function(eventName, fn) {
            for (var e in receiver.subscribers) {
                if (eventName === e) {
                    receiver.subscribers[e] = fn;
                    return;
                }
            }
            WebClient.subscribers[eventName] = fn;
        };
        WebClient.publish = function(eventName, data) {
            for (var e in receiver.subscribers) {
                if (eventName === e) {
                    var fn = receiver.subscribers[e];
                    fn(data);
                    return;
                }
            }
        };
        //获取所有的工程列表
        Socket.on('GetProjects', function() {
            WebClient.OnGetProjects();
        });
        //选择一个工程
        Socket.on('SelectProject', function(prjArray) {
            try {
                if (!prjArray) return;
                WebClient.Name = prjArray;
                //WebClient.EmitData('SelectProject', names);
            } catch (err) {
                return;
            }
        });
        //需要同全站仪交互的命令
        Socket.on('Command', function(cmdData) {
            WebClient.OnCommand(cmdData);
        });


        //向网页发送数据,默认为'Text'事件
        WebClient.EmitData = function(eventName, data) {
            Socket.emit(eventName, data);
        };
        Socket.on('disconnect', function() {
            console.log('Your Client disconnected:' + WebClient.Id);
            WebClient.OnDisConnect(WebClient);
        });
        return WebClient;
    }
};
exports.WebClients = WebClients;
